module.exports = (app) => {
  const {
    STRING,
    DATE,
    INTEGER,
    DOUBLE
  } = app.Sequelize;

  const MergeUserQuestionnaire = app.model.define(
    'MergeUserQuestionnaire',
    {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      uuid: { type: STRING(36), unique: true },
      FKUser: { type: INTEGER, field: 'fk_user' },
      FKQuestionnaire: { type: INTEGER, field: 'fk_questionnaire' },
      email: { type: STRING },
      startTime: { type: DOUBLE, field: 'start_time' },
      endTime: { type: DOUBLE, field: 'end_time' },
      complateFlag: { type: INTEGER, field: 'complate_flag', defaultValue: 0 },
      createdAt: { type: DATE, field: 'created_at' },
      updatedAt: { type: DATE, field: 'updated_at' },
    },
    {
      tableName: 'merge_user_questionnaire'
    }
  );

  MergeUserQuestionnaire.associate = () => {
    app.model.MergeUserQuestionnaire.hasMany(app.model.Answer, {
      foreignKey: 'fk_merge_user_questionnaire',
      sourceKey: 'id',
    });

    app.model.MergeUserQuestionnaire.belongsTo(
      app.model.Questionnaire,
      {
        foreignKey: 'fk_questionnaire',
        sourceKey: 'id',
      }
    );

    app.model.MergeUserQuestionnaire.belongsTo(app.model.User, {
      foreignKey: 'fk_user',
      sourceKey: 'id',
    });
  };

  return MergeUserQuestionnaire;
};
